package com.ruoyi.report_gc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_gc.domain.bo.GcwqxnfxwqxnjlbBsInfoBo;
import com.ruoyi.report_gc.domain.vo.GcwqxnfxwqxnjlbBsInfoVo;
import com.ruoyi.report_gc.domain.GcwqxnfxwqxnjlbBsInfo;
import com.ruoyi.report_gc.mapper.GcwqxnfxwqxnjlbBsInfoMapper;
import com.ruoyi.report_gc.service.IGcwqxnfxwqxnjlbBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 钢材弯曲性能、反向弯曲性能试验检测记录Service业务层处理
 *
 * @author llb
 * @date 2024-07-02
 */
@RequiredArgsConstructor
@Service
public class GcwqxnfxwqxnjlbBsInfoServiceImpl implements IGcwqxnfxwqxnjlbBsInfoService {

    private final GcwqxnfxwqxnjlbBsInfoMapper baseMapper;

    /**
     * 查询钢材弯曲性能、反向弯曲性能试验检测记录
     */
    @Override
    @FIllBasicInfo
    public GcwqxnfxwqxnjlbBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询钢材弯曲性能、反向弯曲性能试验检测记录列表
     */
    @Override
    public TableDataInfo<GcwqxnfxwqxnjlbBsInfoVo> queryPageList(GcwqxnfxwqxnjlbBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<GcwqxnfxwqxnjlbBsInfo> lqw = buildQueryWrapper(bo);
        Page<GcwqxnfxwqxnjlbBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询钢材弯曲性能、反向弯曲性能试验检测记录列表
     */
    @Override
    public List<GcwqxnfxwqxnjlbBsInfoVo> queryList(GcwqxnfxwqxnjlbBsInfoBo bo) {
        LambdaQueryWrapper<GcwqxnfxwqxnjlbBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<GcwqxnfxwqxnjlbBsInfo> buildQueryWrapper(GcwqxnfxwqxnjlbBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<GcwqxnfxwqxnjlbBsInfo> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getTotalPage() != null, GcwqxnfxwqxnjlbBsInfo::getTotalPage, bo.getTotalPage());
        lqw.eq(bo.getPage() != null, GcwqxnfxwqxnjlbBsInfo::getPage, bo.getPage());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), GcwqxnfxwqxnjlbBsInfo::getJiancdwmc, bo.getJiancdwmc());
        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), GcwqxnfxwqxnjlbBsInfo::getJilbh, bo.getJilbh());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), GcwqxnfxwqxnjlbBsInfo::getGongcmc, bo.getGongcmc());
        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), GcwqxnfxwqxnjlbBsInfo::getGongcbwyt, bo.getGongcbwyt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), GcwqxnfxwqxnjlbBsInfo::getYangpmc, bo.getYangpmc());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), GcwqxnfxwqxnjlbBsInfo::getYangpbh, bo.getYangpbh());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), GcwqxnfxwqxnjlbBsInfo::getYangpsl, bo.getYangpsl());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), GcwqxnfxwqxnjlbBsInfo::getYangpzt, bo.getYangpzt());
        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), GcwqxnfxwqxnjlbBsInfo::getYangpsj, bo.getYangpsj());
        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), GcwqxnfxwqxnjlbBsInfo::getShiyjcrq, bo.getShiyjcrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), GcwqxnfxwqxnjlbBsInfo::getShiytjwd, bo.getShiytjwd());
        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), GcwqxnfxwqxnjlbBsInfo::getShiytjsd, bo.getShiytjsd());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), GcwqxnfxwqxnjlbBsInfo::getJiancyj, bo.getJiancyj());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), GcwqxnfxwqxnjlbBsInfo::getPandyj, bo.getPandyj());
        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), GcwqxnfxwqxnjlbBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());

        lqw.eq(bo.getGongczj1() != null, GcwqxnfxwqxnjlbBsInfo::getGongczj1, bo.getGongczj1());
        lqw.eq(bo.getGongcjmj1() != null, GcwqxnfxwqxnjlbBsInfo::getGongcjmj1, bo.getGongcjmj1());
        lqw.eq(bo.getWanqytzj1() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj1, bo.getWanqytzj1());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd1()), GcwqxnfxwqxnjlbBsInfo::getWanqjd1, bo.getWanqjd1());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg1()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg1, bo.getWanqsyjg1());
        lqw.eq(bo.getFanxytzj1() != null, GcwqxnfxwqxnjlbBsInfo::getFanxytzj1, bo.getFanxytzj1());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxjd1()), GcwqxnfxwqxnjlbBsInfo::getFanxjd1, bo.getFanxjd1());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxsyjd1()), GcwqxnfxwqxnjlbBsInfo::getFanxsyjd1, bo.getFanxsyjd1());
        lqw.eq(bo.getWanqytzj2() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj2, bo.getWanqytzj2());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd2()), GcwqxnfxwqxnjlbBsInfo::getWanqjd2, bo.getWanqjd2());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg2()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg2, bo.getWanqsyjg2());
        lqw.eq(bo.getGongczj3() != null, GcwqxnfxwqxnjlbBsInfo::getGongczj3, bo.getGongczj3());
        lqw.eq(bo.getGongcjmj3() != null, GcwqxnfxwqxnjlbBsInfo::getGongcjmj3, bo.getGongcjmj3());
        lqw.eq(bo.getWanqytzj3() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj3, bo.getWanqytzj3());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd3()), GcwqxnfxwqxnjlbBsInfo::getWanqjd3, bo.getWanqjd3());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg3()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg3, bo.getWanqsyjg3());
        lqw.eq(bo.getFanxytzj3() != null, GcwqxnfxwqxnjlbBsInfo::getFanxytzj3, bo.getFanxytzj3());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxjd3()), GcwqxnfxwqxnjlbBsInfo::getFanxjd3, bo.getFanxjd3());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxsyjd3()), GcwqxnfxwqxnjlbBsInfo::getFanxsyjd3, bo.getFanxsyjd3());
        lqw.eq(bo.getWanqytzj4() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj4, bo.getWanqytzj4());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd4()), GcwqxnfxwqxnjlbBsInfo::getWanqjd4, bo.getWanqjd4());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg4()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg4, bo.getWanqsyjg4());
        lqw.eq(bo.getGongczj5() != null, GcwqxnfxwqxnjlbBsInfo::getGongczj5, bo.getGongczj5());
        lqw.eq(bo.getGongcjmj5() != null, GcwqxnfxwqxnjlbBsInfo::getGongcjmj5, bo.getGongcjmj5());
        lqw.eq(bo.getWanqytzj5() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj5, bo.getWanqytzj5());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd5()), GcwqxnfxwqxnjlbBsInfo::getWanqjd5, bo.getWanqjd5());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg5()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg5, bo.getWanqsyjg5());
        lqw.eq(bo.getFanxytzj5() != null, GcwqxnfxwqxnjlbBsInfo::getFanxytzj5, bo.getFanxytzj5());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxjd5()), GcwqxnfxwqxnjlbBsInfo::getFanxjd5, bo.getFanxjd5());
        lqw.eq(StringUtils.isNotBlank(bo.getFanxsyjd5()), GcwqxnfxwqxnjlbBsInfo::getFanxsyjd5, bo.getFanxsyjd5());
        lqw.eq(bo.getWanqytzj6() != null, GcwqxnfxwqxnjlbBsInfo::getWanqytzj6, bo.getWanqytzj6());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqjd6()), GcwqxnfxwqxnjlbBsInfo::getWanqjd6, bo.getWanqjd6());
        lqw.eq(StringUtils.isNotBlank(bo.getWanqsyjg6()), GcwqxnfxwqxnjlbBsInfo::getWanqsyjg6, bo.getWanqsyjg6());
        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), GcwqxnfxwqxnjlbBsInfo::getFujsm, bo.getFujsm());
        lqw.eq(StringUtils.isNotBlank(bo.getJianc()), GcwqxnfxwqxnjlbBsInfo::getJianc, bo.getJianc());
        lqw.eq(StringUtils.isNotBlank(bo.getJil()), GcwqxnfxwqxnjlbBsInfo::getJil, bo.getJil());
        lqw.eq(StringUtils.isNotBlank(bo.getFuh()), GcwqxnfxwqxnjlbBsInfo::getFuh, bo.getFuh());
        lqw.eq(StringUtils.isNotBlank(bo.getRiq()), GcwqxnfxwqxnjlbBsInfo::getRiq, bo.getRiq());
        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), GcwqxnfxwqxnjlbBsInfo::getShebIds, bo.getShebIds());
        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), GcwqxnfxwqxnjlbBsInfo::getPandyjIds, bo.getPandyjIds());
        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), GcwqxnfxwqxnjlbBsInfo::getJiancyjIds, bo.getJiancyjIds());
        return lqw;
    }

    /**
     * 新增钢材弯曲性能、反向弯曲性能试验检测记录
     */
    @Override
    public Boolean insertByBo(GcwqxnfxwqxnjlbBsInfoBo bo) {
        GcwqxnfxwqxnjlbBsInfo add = BeanUtil.toBean(bo, GcwqxnfxwqxnjlbBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改钢材弯曲性能、反向弯曲性能试验检测记录
     */
    @Override
    public Boolean updateByBo(GcwqxnfxwqxnjlbBsInfoBo bo) {
        GcwqxnfxwqxnjlbBsInfo update = BeanUtil.toBean(bo, GcwqxnfxwqxnjlbBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(GcwqxnfxwqxnjlbBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除钢材弯曲性能、反向弯曲性能试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
